package com.ruoyi.web.controller.hotel;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hotel.domain.LyhmsRoomType;
import com.ruoyi.hotel.service.ILyhmsRoomTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Controller
 * @author ruoyi
 * @date 2022-02-28
 */
@RestController
@RequestMapping("/system/type")
public class LyhmsRoomTypeController extends BaseController {
    @Autowired
    private ILyhmsRoomTypeService lyhmsRoomTypeService;

    /**
     * 查询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LyhmsRoomType lyhmsRoomType) {
        startPage();
        Long deptId = SecurityUtils.getCurrentDeptId();
        lyhmsRoomType.setDeptId(deptId);
        List<LyhmsRoomType> list = lyhmsRoomTypeService.selectLyhmsRoomTypeList(lyhmsRoomType);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
    @Log(title = "", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LyhmsRoomType lyhmsRoomType) {
        List<LyhmsRoomType> list = lyhmsRoomTypeService.selectLyhmsRoomTypeList(lyhmsRoomType);
        ExcelUtil<LyhmsRoomType> util = new ExcelUtil<LyhmsRoomType>(LyhmsRoomType.class);
        util.exportExcel(response, list, "数据");
    }

    /**
     * 获取详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(lyhmsRoomTypeService.selectLyhmsRoomTypeById(id));
    }

    /**
     * 新增
     */
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LyhmsRoomType lyhmsRoomType) {
        return toAjax(lyhmsRoomTypeService.insertLyhmsRoomType(lyhmsRoomType));
    }

    /**
     * 修改
     */
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LyhmsRoomType lyhmsRoomType) {
        return toAjax(lyhmsRoomTypeService.updateLyhmsRoomType(lyhmsRoomType));
    }

    /**
     * 删除
     */
    @Log(title = "", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(lyhmsRoomTypeService.deleteLyhmsRoomTypeByIds(ids));
    }


    @GetMapping("ListNames")
    public AjaxResult ListNames() {
        LyhmsRoomType lyhmsRoomType = new LyhmsRoomType();
        List<LyhmsRoomType> list = lyhmsRoomTypeService.selectLyhmsRoomTypeList(lyhmsRoomType);
        return AjaxResult.success().put("list", list);
    }

    @GetMapping("byName/{type}")
    public AjaxResult selectInfo(@PathVariable("type") String type) {
        return AjaxResult.success(lyhmsRoomTypeService.selectLyhmsRoomTypeByName(type));
    }
}
